package org.rslai.tcedit.dao.hibernate;

import java.util.List;
import org.rslai.tcedit.dao.CatalogDao;
import org.rslai.tcedit.domain.Catalog;

/**
 * CatalogDao的实现类
 * 
 * @author rslai
 * 
 * @spring.bean id="catalogDao"
 */
public class CatalogImpl extends GenericDynamicTableHibernateDao<Catalog> implements CatalogDao {

	public CatalogImpl() {
		super(Catalog.class);
	}

	@SuppressWarnings("unchecked")
	public List<Catalog> query(String productID, String versionID, String parentCatalogID, boolean asc) {
		StringBuffer sqlStr = new StringBuffer();

		sqlStr.append("from " + this.getEntityName(productID) + " as a where version.id=? and parentCatalogID=?");
		if (asc) {
			sqlStr.append(" order by a.sequence");
		} else {
			sqlStr.append(" order by a.sequence desc");
		}

    	return queryForList(
				sqlStr.toString(), 
				new Object[] { versionID, parentCatalogID }
		);
	}

	public Long countCatalog(String productID, String catalogID) {
		return (Long)queryForObject(
				"select count(*) from " + this.getEntityName(productID) + " as a where parentCatalogID=?",
				new Object[] { catalogID }
		);
	}

}
